<?php
class ZtuansController extends AppController {

	var $name = 'Ztuans';

	function index() {
		$this->Ztuan->recursive = 0;
		$this->set('ztuans', $this->paginate());
	}
    
    function chitieutt($thang_id=null) {
		$this->Ztuan->recursive = 0;
        $thang=$this->Ztuan->query('select tentg from zthangs where id='.$thang_id);
        $tuan = $this->Ztuan->query("select ztuans.id, ztuans.tentg, ztuans.ngaybd, ztuans.ngaykt 
                                        from ztuans, zthangs 
                                        where ztuans.ngaybd between zthangs.ngaybd and zthangs.ngaykt
                                        and ztuans.ngaykt between zthangs.ngaybd and zthangs.ngaykt
                                        and zthangs.id=".$thang_id);
        print_r($thang);
        $this->set(compact('thang_id','tuan','thang'));
		//$this->set('ztuans', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid ztuan', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('ztuan', $this->Ztuan->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Ztuan->create();
			if ($this->Ztuan->save($this->data)) {
				$this->Session->setFlash(__('The ztuan has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The ztuan could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid ztuan', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Ztuan->save($this->data)) {
				$this->Session->setFlash(__('The ztuan has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The ztuan could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Ztuan->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for ztuan', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Ztuan->delete($id)) {
			$this->Session->setFlash(__('Ztuan deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Ztuan was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
